/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thesis.haipv.qa.persistence;

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;

/**
 *
 * @author PHANHAI
 */
public class DatabaseContext {

    private static DatabaseContext instance = null;
    private Connection conn = null;
    private String dbname;
    private String uname;
    private String pname;

    private DatabaseContext() {
        connect();
    }

    public static DatabaseContext getInstance() {
        if (instance == null) {
            instance = new DatabaseContext();
        }
        return instance;
    }

    public Connection getConnection() {
        return conn;
    }

    private void connect() {
        String dbUrl = "jdbc:mysql://localhost:3306/thesis_qa?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true";
        String dbClass = "com.mysql.jdbc.Driver";
        try {
            Class.forName(dbClass);
            conn = (Connection) DriverManager.getConnection(dbUrl, "root", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
